package com.hnichr.ump.business.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hnichr.ump.common.doc.entity.OrderLog;
import com.hnichr.ump.common.doc.service.OrderLogService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import com.mxpioframework.jpa.query.Order;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

@RestController
@RequestMapping("/doc/orderlog/v1/")
@Tag(name = "OrderLogController", description = "文印商城订单动态接口")
public class OrderLogController {
	@Autowired
	private OrderLogService orderLogService;

	@GetMapping("page")
	@Operation(summary = "订单动态列表", description = "获取订单动态列表", method = "GET")
	public Result<Page<OrderLog>> page(@Parameter(description = "查询参数") Criteria criteria,
			@Parameter(description = "每页条数") Integer pageSize, @Parameter(description = "页号") Integer pageNo) {
		Pageable page = PageRequest.of(pageNo - 1, pageSize);
		Page<OrderLog> list = orderLogService.listPage(OrderLog.class, page, criteria);
		return Result.OK(list);
	}

	@GetMapping("list")
	@Operation(summary = "订单动态列表", description = "获取订单动态列表（无分页）", method = "GET")
	public Result<List<OrderLog>> list(@RequestParam("orderId") String orderId) {
		Criteria criteria = Criteria.create();
		criteria.addCriterion("orderId", Operator.EQ, orderId);
		criteria.addOrder(new Order("createTime", true));
		List<OrderLog> list = orderLogService.list(OrderLog.class, criteria);
		return Result.OK(list);
	}
}
